(function(vc, vm) {

    vc.extends({
        data: {
            editProductPriceRuleInfo: {
                ruleId: '',
                ruleId: '',
                ruleName: '',
                price: '',
                otPrice: '',
                vipPrice: '',
                ownerPrice: '',
                deduction: '',
                ruleType: '',
                priceBase: '1',
                otPriceBase: '1',
                vipPriceBase: '1',
                ownerPriceBase: '1',
            }
        },
        _initMethod: function() {

        },
        _initEvent: function() {
            vc.on('editProductPriceRule', 'openEditProductPriceRuleModal', function(_params) {
                $that.refreshEditProductPriceRuleInfo();
                $('#editProductPriceRuleModel').modal('show');
                vc.copyObject(_params, $that.editProductPriceRuleInfo);
                $that.editProductPriceRuleInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editProductPriceRuleValidate: function() {
                return vc.validate.validate({
                    editProductPriceRuleInfo: $that.editProductPriceRuleInfo
                }, {
                    'editProductPriceRuleInfo.ruleId': [{
                            limit: "required",
                            param: "",
                            errInfo: "策略编号不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "策略编号不能超过30"
                        },
                    ],
                    'editProductPriceRuleInfo.ruleName': [{
                            limit: "required",
                            param: "",
                            errInfo: "策略名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "策略名称不能超过64"
                        },
                    ],
                    'editProductPriceRuleInfo.price': [{
                            limit: "required",
                            param: "",
                            errInfo: "销售金额不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "8",
                            errInfo: "销售金额不能超过8"
                        },
                    ],
                    'editProductPriceRuleInfo.otPrice': [{
                            limit: "required",
                            param: "",
                            errInfo: "市场价不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "8",
                            errInfo: "市场价不能超过8"
                        },
                    ],
                    'editProductPriceRuleInfo.vipPrice': [{
                            limit: "required",
                            param: "",
                            errInfo: "会员价不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "8",
                            errInfo: "会员价不能超过8"
                        },
                    ],
                    'editProductPriceRuleInfo.ownerPrice': [{
                            limit: "required",
                            param: "",
                            errInfo: "业主价不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "8",
                            errInfo: "业主价不能超过8"
                        },
                    ],
                    'editProductPriceRuleInfo.deduction': [{
                            limit: "required",
                            param: "",
                            errInfo: "物业抵扣金'不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "8",
                            errInfo: "物业抵扣金'不能超过8"
                        },
                    ],
                    'editProductPriceRuleInfo.ruleId': [{
                        limit: "required",
                        param: "",
                        errInfo: "策略编号不能为空"
                    }]

                });
            },
            editProductPriceRule: function() {
                if (!$that.editProductPriceRuleValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/productPriceRule.updateProductPriceRule',
                    JSON.stringify($that.editProductPriceRuleInfo), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editProductPriceRuleModel').modal('hide');
                            vc.emit('productPriceRuleManage', 'listProductPriceRule', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshEditProductPriceRuleInfo: function() {
                $that.editProductPriceRuleInfo = {
                    ruleId: '',
                    ruleId: '',
                    ruleName: '',
                    price: '',
                    otPrice: '',
                    vipPrice: '',
                    ownerPrice: '',
                    deduction: '',
                    ruleType: '',
                    priceBase: '1',
                    otPriceBase: '1',
                    vipPriceBase: '1',
                    ownerPriceBase: '1',
                }
            }
        }
    });

})(window.vc, window.vc.component);